import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:wallet_utils/report_widget/base/callback/base_callback.dart';
import 'package:wallet_utils/toast.dart';
import 'package:wallet_utils/webview_common.dart';
import '../../agreement_dialog.dart';
import '../api/hxh_api.dart';
import '../bean/hxhAuditResultBean.dart';
import '../bean/hxhConfirmLoanBean.dart';
import '../bean/hxhOrderBean.dart';
import '../bean/hxhOrderResultBean.dart';
import '../bean/hxhOrderStatusBean.dart';
import 'state.dart';

class HXHOrderDetailsLogic extends GetxController {
  final HXHOrderDetailsState state = HXHOrderDetailsState();
    String orderNo ='';
  List<OrderList>? orderList = [];
  @override
  void onInit() {
    super.onInit();
    if (Get.arguments != null) {
      orderNo = Get.arguments['orderNo'];
    }
    getOrderStatus();
  }

  //订单状态
  getOrderStatus() {
    HXHApi.getOrderStatus(
        orderNo,
        BaseCallback(onSuccess: (map) {
          HxhOrderResultBean resultBean = HxhOrderResultBean.fromJson(map);
          if (resultBean.data != null) {
            state.institutionProductName =
                '恒小花';
            state.updateTime = resultBean.data?.updateTime;
            state.auditAmount = (resultBean.data?.auditAmount)!/100;
            state.auditPeriodNum = resultBean.data?.auditPeriodNum;
            state.yearRate = (resultBean.data?.yearRate)!*100;
            state.status = resultBean.data?.status;
            update();
          } else {
            //审核失败
            ToastUtils.showToast("获取信息失败");
          }
        }, onError: (msg) {
          Future.delayed(const Duration(milliseconds: 500), () {
            ToastUtils.showToast(msg ?? "");
            update();
          });
        }));
  }
  //获取订单状态
getOrderStatusTitle(){
  //150:待签约152:绑卡成功250：签约中190：待放款(签约成功)200：放款失败210：放款成功211：还款正常220：已逾期230：提前结清240：正常结清160：取消订单，比如:超过签约时效，自动取消订单245：紧急划回260：用户放弃
  if(state.status==150){
    return '待签约';
  }else if(state.status==152){
    return '绑卡成功';
  }else if(state.status==250){
    return '签约中';
  }else if(state.status==190){
    return '待放款';
  }else if(state.status==200){
    return '放款失败';
  }else if(state.status==210){
    return '放款成功';
  }else if(state.status==220){
    return '已逾期';
  }else{
    return '';
  }
}

}
